<html>
<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<body>
<script type="text/javascript" src="./$.js"></script>
<script>
    require(['!this.js'], $$.load)
</script>
</body>
</html>
<template data-name="this.htm">
    <div>
        <div class="head">
            <div class="head_box">
                <div class="inner wrp"><h1 class="logo"></h1></div>
            </div>
            <div class="banner">
                <div class="inner wrp">
                    <div class="login_frame"><h3>登录</h3>
                        <div class="login_err_panel" v-if="error">{{error}}</div>
                        <form class="login_form" id="loginForm">
                            <div class="login_input_panel" id="js_mainContent">
                                <div class="login_input"><i class="icon_login un"> </i>
                                    <input type="text" placeholder="用户名" v-model="user_id" @keyup.13="go_login">
                                </div>
                                <div class="login_input"><i class="icon_login pwd"> </i>
                                    <input type="password" placeholder="密码">
                                </div>
                            </div>
                            <div class="login_help_panel">
                                <a class="login_forget_pwd" href="">忘记密码</a>
                            </div>
                            <div class="login_btn_panel">
                                <a class="btn_login" title="点击登录" @click="go_login">登录</a>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <foot></foot>
    </div>
</template>
<script data-name="this.js">
    function get_data(callback) {
        $$.ajax({
            url: "/sys/open/login",
            data: {auth_code: $$.m.auth_code, user_id: $$.m.user_id},
            result: {
                $200: function (data) {
                    callback(data);
                },
                $400: function (data) {
                    $$.m.error = data.msg;
                }
            }
        });
    }
    require('../$res/css/login.css');
    require('../$res/js/common');
    $$.c.auth = false;
    module.exports = {
        template: require('!this.htm'),
        methods: {
            go_login: function () {
                $$.toast.show('登录中...');
                get_data(function (ret) {
                    $$.localConfig(ret.data.config);
                    $$.localStore('menu', ret.data.menu);
                    $$.localStore('userInfo', ret.data.user_info);
                    setTimeout(function () {
                        if ($$.c.query.url)
                            location.replace($$.c.query.url);
                        else
                            location.replace('/sys/home/index.html');
                    }, 0)
                })
            }
        },
        components: {
            'foot': require("../$res/component/foot")
        },
        loaded: function () {
            $$.m = {
                auth_code: $$.c.query.auth_code,
                user_id: '',
                error: ''
            };
            if ($$.m.auth_code)
                get_data(function (ret) {
                    $$.localConfig(ret.data.config);
                    $$.localStore('menu', ret.data.menu);
                    $$.localStore('userInfo', ret.data.user_info);
                    setTimeout(function () {
                        if ($$.c.query.url)
                            location.replace($$.c.query.url);
                        else
                            location.replace('/sys/home/index.html');
                    }, 0)
                })
        }
    };
</script>
